function KDE_datasave(X)

bandfig=figure( ...
   'Visible','on', ...
   'Name','Data Saving', ...
   'Units','Normalized',...
   'Tag','KDE_DATASAVE',...
   'NumberTitle','off');

uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.2,.8,.6,.1], ...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.5,...
        'String','Choose variables to save:');

Xsave=uicontrol( ...
        'Style','checkbox', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.2,.7,.6,.075], ...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'Tag','KDE_SAVE_X',...
        'String',' Random variable - X');

Ksave=uicontrol( ...
        'Style','checkbox', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.2,.6,.6,.075], ...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'Tag','KDE_SAVE_K',...
        'String',' Kernel - K');

hsave=uicontrol( ...
        'Style','checkbox', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.2,.5,.6,.075], ...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'Tag','KDE_SAVE_h',...
        'String',' Bandwidth - h');

xsave=uicontrol( ...
        'Style','checkbox', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.2,.4,.6,.075], ...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'Tag','KDE_SAVE_xx',...
        'String',' Points of x-axis  - xx');

festsave=uicontrol( ...
        'Style','checkbox', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.2,.3,.6,.075], ...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'Tag','KDE_SAVE_f',...
        'String',' Kernel estimate in points xx - f_est');

sdata0='mf=findobj(''Tag'',''KDE_MAIN'');udata=get(mf,''UserData'');X=udata.X;K=udata.K;h=udata.h;xx=udata.xx;f_est=udata.f_est;';
sdata1='varlist=[];v_hand=findobj(''Tag'',''KDE_SAVE_X'');v_use=get(v_hand,''Value'');if v_use, varlist=[varlist,'',''''X''''''];end;';
sdata2='v_hand=findobj(''Tag'',''KDE_SAVE_K'');v_use=get(v_hand,''Value'');if v_use, varlist=[varlist,'',''''K''''''];end;';
sdata3='v_hand=findobj(''Tag'',''KDE_SAVE_h'');v_use=get(v_hand,''Value'');if v_use, varlist=[varlist,'',''''h''''''];end;';
sdata4='v_hand=findobj(''Tag'',''KDE_SAVE_xx'');v_use=get(v_hand,''Value'');if v_use, varlist=[varlist,'',''''xx''''''];end;';
sdata5='v_hand=findobj(''Tag'',''KDE_SAVE_f'');v_use=get(v_hand,''Value'');if v_use, varlist=[varlist,'',''''f_est''''''];end;';
sdata6='if length(varlist)>0, varlist(1)=[]; savecmd=[''uisave({'',varlist,''},''''KDE_data'''');''];eval(savecmd);close(gcf); end;';
datatsave=uicontrol( ...
        'Style','Push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.2,.21,.4,.075], ...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'Tag','KDE_SAVE_DATA',...
        'String','Save selected variables to file', ...
        'Callback',[sdata0,sdata1,sdata2,sdata3,sdata4,sdata5,sdata6]);




save KDE_tempsavedata

wdata0='mf=findobj(''Tag'',''KDE_MAIN'');udata=get(mf,''UserData'');X=udata.X;K=udata.K;h=udata.h;xx=udata.xx;f_est=udata.f_est;';
wdata1='varlist=[];v_hand=findobj(''Tag'',''KDE_SAVE_X'');v_use=get(v_hand,''Value'');if v_use, varlist=[varlist,'',''''X''''''];end;';
wdata2='v_hand=findobj(''Tag'',''KDE_SAVE_K'');v_use=get(v_hand,''Value'');if v_use, varlist=[varlist,'',''''K''''''];end;';
wdata3='v_hand=findobj(''Tag'',''KDE_SAVE_h'');v_use=get(v_hand,''Value'');if v_use, varlist=[varlist,'',''''h''''''];end;';
wdata4='v_hand=findobj(''Tag'',''KDE_SAVE_xx'');v_use=get(v_hand,''Value'');if v_use, varlist=[varlist,'',''''xx''''''];end;';
wdata5='v_hand=findobj(''Tag'',''KDE_SAVE_f'');v_use=get(v_hand,''Value'');if v_use, varlist=[varlist,'',''''f_est''''''];end;';
wdata6='if length(varlist)>0, varlist(1)=[]; savecmd=[''save(''''KDE_tempsavedata'''',''''-append'''',{'',varlist,''});''],eval(savecmd);close(gcf); end;';
workspacesave=uicontrol( ...
        'Style','Push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.2,.05,.4,.075], ...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'Tag','KDE_SAVE_DATA',...
        'String','Add selected variables to workspace', ...
        'Callback',[wdata0,wdata1,wdata2,wdata3,wdata4,wdata5,wdata6]);


